#ifndef _LOADER_
#define _LOADER_

#include <vector>
#include <string>
#include "Utility.h"

template < class T >
class Loader
{
public:
	Loader(std::string message, std::string filename, std::vector< T >& items)
	{
		std::string line = "";
		std::cout << message << std::endl;
		std::ifstream item_stream(filename.c_str());

		if (item_stream.fail())
		{
			std::cout << "Could not locate the file \"" << filename << "\"" << std::endl;
		}

		while (std::getline(item_stream, line))
		{
			std::istringstream line_stream(line);
			if (line != "")
				items.push_back( T(line_stream) );
		}

		item_stream.close();
	}

	Loader(std::string message, std::string filename, std::vector< T >& items, int header)
	{
		std::string line = "";
		std::cout << message << std::endl;
		std::ifstream item_stream(filename.c_str());

		if (item_stream.fail())
		{
			std::cout << "Could not locate the file \"" << filename << "\"" << std::endl;
		}

		// Consume the header lines
		for ( int i = 0; i < header; ++i)
			std::getline(item_stream, line);

		while (std::getline(item_stream, line))
		{
			std::istringstream line_stream(line);
			if (line != "")
				items.push_back( T(line_stream) );
		}

		item_stream.close();
	}

	Loader(std::string filename, std::vector< int >& items)
	{
		std::cout << "Loading date data. . ." << std::endl;
		std::ifstream item_stream(filename.c_str());

		if (item_stream.fail())
		{
			std::cout << "Could not locate the file \"" << filename << "\"" << std::endl;
		}

		std::string line = "";
		while (std::getline(item_stream, line))
		{
			std::istringstream line_stream(line);
			if (line != "")
				items.push_back( util::string_to_int(line_stream.str()) );
		}

		item_stream.close();
	}
};

#endif